//
// Copyright (C) 2011 - 2013  Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1
//#include "stdafx.h"
#include "GaussJacobiPolynomial.h"
using namespace Cephei::QL::Math::Integrals;
#include <gen/QL/Math/Integrals/GaussianOrthogonalPolynomial.h>
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Math::Integrals::CGaussJacobiPolynomial::CGaussJacobiPolynomial (Double alpha, Double beta) : CGaussianOrthogonalPolynomial(CGaussJacobiPolynomial::typeid)
{
    try
    {
#ifdef HANDLE
        _phGaussJacobiPolynomial = NULL;
#endif
        QuantLib::Real _alpha = (QuantLib::Real)ValueHelper::Convert (alpha); //d
        QuantLib::Real _beta = (QuantLib::Real)ValueHelper::Convert (beta); //d
        _ppGaussJacobiPolynomial = new boost::shared_ptr<QuantLib::GaussJacobiPolynomial> (new QuantLib::GaussJacobiPolynomial ( _alpha,  _beta ));
        SetGaussianOrthogonalPolynomial (boost::dynamic_pointer_cast<QuantLib::GaussianOrthogonalPolynomial> (*_ppGaussJacobiPolynomial));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Math::Integrals::CGaussJacobiPolynomial::CGaussJacobiPolynomial (boost::shared_ptr<QuantLib::GaussJacobiPolynomial>& childNative, Object^ owner) : CGaussianOrthogonalPolynomial(CGaussJacobiPolynomial::typeid)
{
#ifdef HANDLE
	_phGaussJacobiPolynomial = NULL;
#endif
	_ppGaussJacobiPolynomial = &childNative;
    _ppGaussianOrthogonalPolynomial = new boost::shared_ptr<QuantLib::GaussianOrthogonalPolynomial> (boost::dynamic_pointer_cast<QuantLib::GaussianOrthogonalPolynomial> (*_ppGaussJacobiPolynomial));
}
Cephei::QL::Math::Integrals::CGaussJacobiPolynomial::CGaussJacobiPolynomial (QuantLib::GaussJacobiPolynomial& childNative, Object^ owner) : CGaussianOrthogonalPolynomial(CGaussJacobiPolynomial::typeid)
{
#ifdef HANDLE
	_phGaussJacobiPolynomial = NULL;
#endif
	_ppGaussJacobiPolynomial = new boost::shared_ptr<QuantLib::GaussJacobiPolynomial> (&childNative);
    _ppGaussianOrthogonalPolynomial = new boost::shared_ptr<QuantLib::GaussianOrthogonalPolynomial> (boost::dynamic_pointer_cast<QuantLib::GaussianOrthogonalPolynomial> (*_ppGaussJacobiPolynomial));
    _GaussJacobiPolynomialOwner = owner;
    _GaussianOrthogonalPolynomialOwner = owner;
}

Cephei::QL::Math::Integrals::CGaussJacobiPolynomial::CGaussJacobiPolynomial (CGaussJacobiPolynomial^ copy) : CGaussianOrthogonalPolynomial(CGaussJacobiPolynomial::typeid)
{
#ifdef HANDLE
	_phGaussJacobiPolynomial = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppGaussJacobiPolynomial = new boost::shared_ptr<QuantLib::GaussJacobiPolynomial> (copy->GetShared());
        _ppGaussianOrthogonalPolynomial = new boost::shared_ptr<QuantLib::GaussianOrthogonalPolynomial> (boost::dynamic_pointer_cast<QuantLib::GaussianOrthogonalPolynomial> (*_ppGaussJacobiPolynomial));
    }
}
Cephei::QL::Math::Integrals::CGaussJacobiPolynomial::CGaussJacobiPolynomial (PLATFORM::Type^ t) : CGaussianOrthogonalPolynomial(CGaussJacobiPolynomial::typeid)
{
#ifdef HANDLE
	_phGaussJacobiPolynomial = NULL;
#endif
	if (!t->IsSubclassOf(CGaussJacobiPolynomial::typeid))
		throw REFNEW Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Math::Integrals::CGaussJacobiPolynomial::CGaussJacobiPolynomial (QuantLib::Handle<QuantLib::GaussJacobiPolynomial>& childNative, Object^ owner)  : CGaussianOrthogonalPolynomial(CGaussJacobiPolynomial::typeid)
{
	_phGaussJacobiPolynomial = &childNative;
	_ppGaussJacobiPolynomial = &static_cast<boost::shared_ptr<QuantLib::GaussJacobiPolynomial>>(childNative.currentLink());
    _ppGaussianOrthogonalPolynomial = new boost::shared_ptr<QuantLib::GaussianOrthogonalPolynomial> (boost::dynamic_pointer_cast<QuantLib::GaussianOrthogonalPolynomial> (*_ppGaussJacobiPolynomial));
    _GaussJacobiPolynomialOwner = owner;
}
Cephei::QL::Math::Integrals::CGaussJacobiPolynomial::CGaussJacobiPolynomial (QuantLib::Handle<QuantLib::GaussJacobiPolynomial> childNative)  : CGaussianOrthogonalPolynomial(CGaussJacobiPolynomial::typeid)
{
	_phGaussJacobiPolynomial = &childNative;
	_ppGaussJacobiPolynomial = &static_cast<boost::shared_ptr<QuantLib::GaussJacobiPolynomial>>(childNative.currentLink());
    _ppGaussianOrthogonalPolynomial = new boost::shared_ptr<QuantLib::GaussianOrthogonalPolynomial> (boost::dynamic_pointer_cast<QuantLib::GaussianOrthogonalPolynomial> (*_ppGaussJacobiPolynomial));
}
#endif
#ifdef STRUCT
Cephei::QL::Math::Integrals::CGaussJacobiPolynomial::CGaussJacobiPolynomial (QuantLib::GaussJacobiPolynomial childNative)  : CGaussianOrthogonalPolynomial(CGaussJacobiPolynomial::typeid)
{
#ifdef HANDLE
	_phGaussJacobiPolynomial = NULL;
#endif
	_ppGaussJacobiPolynomial = new boost::shared_ptr<QuantLib::GaussJacobiPolynomial> (new QuantLib::GaussJacobiPolynomial (childNative));
    _ppGaussianOrthogonalPolynomial = new boost::shared_ptr<QuantLib::GaussianOrthogonalPolynomial> (boost::dynamic_pointer_cast<QuantLib::GaussianOrthogonalPolynomial> (*_ppGaussJacobiPolynomial));
}
#endif

Cephei::QL::Math::Integrals::CGaussJacobiPolynomial::~CGaussJacobiPolynomial ()
{
    if (_ppGaussJacobiPolynomial != NULL)
    {
	    delete _ppGaussJacobiPolynomial;
        _ppGaussJacobiPolynomial = NULL;
    }
}
Cephei::QL::Math::Integrals::CGaussJacobiPolynomial::!CGaussJacobiPolynomial ()
{
    if (_ppGaussJacobiPolynomial != NULL)
    {
	    delete _ppGaussJacobiPolynomial;
    }
}
QuantLib::GaussJacobiPolynomial& Cephei::QL::Math::Integrals::CGaussJacobiPolynomial::GetReference ()
{
    if (_ppGaussJacobiPolynomial == NULL) throw REFNEW NativeNullException ();
	return **_ppGaussJacobiPolynomial;
}
boost::shared_ptr<QuantLib::GaussJacobiPolynomial>& Cephei::QL::Math::Integrals::CGaussJacobiPolynomial::GetShared ()
{
    if (_ppGaussJacobiPolynomial == NULL) throw REFNEW NativeNullException ();
	return *_ppGaussJacobiPolynomial;
}
QuantLib::GaussJacobiPolynomial* Cephei::QL::Math::Integrals::CGaussJacobiPolynomial::GetPointer ()
{
    if (_ppGaussJacobiPolynomial == NULL) throw REFNEW NativeNullException ();
	return &**_ppGaussJacobiPolynomial;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::GaussJacobiPolynomial>& Cephei::QL::Math::Integrals::CGaussJacobiPolynomial::GetHandle ()
{
	if (_phGaussJacobiPolynomial == NULL)
	{
		_phGaussJacobiPolynomial = new Handle<QuantLib::GaussJacobiPolynomial> (*_ppGaussJacobiPolynomial);
	}
	return *_phGaussJacobiPolynomial;
}
#endif
bool Cephei::QL::Math::Integrals::CGaussJacobiPolynomial::HasNative () 
{
	return (_ppGaussJacobiPolynomial != NULL);
}

Double Cephei::QL::Math::Integrals::CGaussJacobiPolynomial::Alpha (UInt64 i)
{
    try
    {
        QuantLib::Size _i = (QuantLib::Size)ValueHelper::Convert (i); //a
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppGaussJacobiPolynomial)->alpha ( _i );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Math::Integrals::CGaussJacobiPolynomial::Beta (UInt64 i)
{
    try
    {
        QuantLib::Size _i = (QuantLib::Size)ValueHelper::Convert (i); //a
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppGaussJacobiPolynomial)->beta ( _i );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Math::Integrals::CGaussJacobiPolynomial::Mu_0::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppGaussJacobiPolynomial)->mu_0 ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Math::Integrals::CGaussJacobiPolynomial::W (Double x)
{
    try
    {
        QuantLib::Real _x = (QuantLib::Real)ValueHelper::Convert (x); //a
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppGaussJacobiPolynomial)->w ( _x );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Math::Integrals::IGaussJacobiPolynomial^ Cephei::QL::Math::Integrals::CGaussJacobiPolynomial_Factory::Create (Double alpha, Double beta)
{
    return REFNEW CGaussJacobiPolynomial ( alpha,  beta);
}
